<script type="text/javascript" charset="utf-8">
    function deleteGroup(caller) {
        $.post(caller.attr("href"), null, function(data) {
            if (data.success) {
                caller.parent("li").hide();
            }
        });
        return false;
    }

    $(document).ready(function() {
        $(".groupdelete").click(function() {
            return deleteGroup($(this));
        });
    })
</script>
<?php
    $user = Zend_Auth::getInstance()->getIdentity();
    $addgroupUrl = $this->url(array(), "newgroup", true);
?>
<h2>Group list</h2>
<p class="groupAdd"><a href="<?php echo $addgroupUrl ?>">Add group</a></p>
<ul class="grouplist">
<?php
    foreach ($this->groups as $group) {
        echo '<li class="groupTitle"><a href="' . $this->url(array("id" => $group->id()), "groupview", true) .'">' . $group->name() . '</a> ';
        if ($group->can_delete($user)) { ?>
    <a class="groupdelete" href="<?php echo $this->url(array("id" => $group->id()), "groupdelete", true) ?>"><img src="/images/cross .png" alt="Delete!"/></a>
<?php
        }
        echo "</li>";
    }
?>
</ul>
<p class="groupAdd"><a href="<?php echo $addgroupUrl ?>">Add group</a></p>